package parser;

import model.Item;

import org.apache.log4j.Logger;
import org.htmlcleaner.TagNode;

public class ItemParser {

	public Item parse(TagNode node) {

		Item item = new Item();

		if (node.getAttributeByName("id").equals("ttable1")) {
			item.setType(ParserConstants.IDA);
		}

		if (node.getAttributeByName("id").equals("ttable2")) {
			item.setType(ParserConstants.VUELTA);
		}

		String[] daysValue;

		daysValue = node.getText().toString().split("EUR");

		for (int i = 0; i < daysValue.length; i++) {
			String day = new String();
			day = daysValue[i];
			item.addDayToWeekAvailable(day);
		}
		
		return item;

	}

}
